<template>
  <view class="main">
    <view class="tjsj">
      <view
        @tap="tzsjxq"
        :class="
          'sjlb flex-row ' + (item.is_yy == 2 && mdxx.isyykg == 1 ? 'bszz' : '')
        "
        :data-sjid="item.store_id"
        v-for="(item, index) in storelist"
        :key="index"
      >
        <view class="sjleft flex-grow-0">
          <image class="sjleftimg" :src="item.logo"></image>
          <view class="xzhiding" v-if="item.is_brand == '1'">品牌</view>
        </view>

        <view class="sjright flex-grow-1 flex-col">
          <view class="sjright1 flex-row flex-y-center">
            <view class="sjright1-l gobyndsingle">{{ item.name }}</view>
            <view class="isyy" v-if="item.is_yy == 2 && mdxx.isyykg == 1"
              >休息中</view
            >
          </view>
          <view class="sjright2 flex-bet flex-y-center">
            <view class="flex-row flex-grow-1 flex-y-center">
              <view class="pingjia_fenshu3">
                <view class="kximg">
                  <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/i-star.png"></image>
                </view>
                <view class="sximg" :style="'width: ' + item.sales * 20 + '%'">
                  <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/i-stars.png"></image>
                </view>
              </view>
              <view class="pingfen">{{ item.sales }}</view>
              <view class="recommed_midel">月售{{ item.score }}单</view>
            </view>
          </view>
        </view>
      </view>
      <view class="jzz" v-if="!mygd">
        <image class="Rotation" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/jzz.png"></image>
        <view>加载中...</view>
      </view>
      <view class="kong" v-if="storelist.length == 0 && mygd">
        <image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/wushuju.png"></image>
        <view>暂无相关数据</view>
      </view>
      <view class="jzwb" v-if="mygd">
        <view class="hx"></view>
        <view class="wz">加载完毕</view>
        <view class="hx"></view>
      </view>
    </view>
  </view>
</template>

<script>
import cardlist from '@/ymq_canyino2o/dist/cardlist/index'
import gettel from '@/ymq_canyino2o/dist/gettel/index'
var app = getApp()
export default {
  components: {
    cardlist,
    gettel
  },
  data() {
    return {
      pagenum: 1,
      storelist: [],
      bfstorelist: [],
      mygd: false,
      jzgd: true,
      isjzz: true,

      params: {
        user_id: uni.getStorageSync('users').id
      },

      mdxx: {
        isyykg: 0
      }
    }
  },
  onLoad: function (t) {
    app.globalData.setNavigationBarColor(this)
    uni.setNavigationBarTitle({
      title: '我的收藏'
    })
    var that = this
    app.globalData.util.request({
      url: 'entry/wxapp/system',
      cachetime: '0',
      success: function (t) {
        console.log(t)
        that.setData({
          mdxx: t.data
        })
      }
    })
    that.getstorelist()
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {
    console.log('上拉加载', this.pagenum)
    this.mygd ||
      !this.jzgd ||
      this.isjzz ||
      (this.setData({
        jzgd: false
      }),
      this.getstorelist())
  },
  methods: {
    tzsjxq: function (t) {
      console.log(t.currentTarget.dataset.sjid, this.mdxx)
      if ('1' == this.mdxx.is_tzms) {
        getApp().globalData.sjid = t.currentTarget.dataset.sjid
        uni.navigateTo({
          url: '/ymq_canyino2o/pages/seller/index'
        })
      } else {
        uni.navigateTo({
          url:
            '/ymq_canyino2o/pages/takeout/takeoutindex?storeid=' +
            t.currentTarget.dataset.sjid
        })
      }
    },

    getstorelist: function () {
      var that = this
      var i = that.pagenum
      that.params.page = i
      that.params.pagesize = 10
      console.log(i, that.params)
      that.setData({
        isjzz: true
      })
      app.globalData.util.request({
        url: 'entry/wxapp/MyStoreCollection',
        cachetime: '0',
        data: that.params,
        success: function (t) {
          console.log('分页返回的商家列表数据', t.data)
          if (t.data.length < 10) {
            that.setData({
              mygd: true,
              jzgd: true,
              isjzz: false
            })
          } else {
            that.setData({
              jzgd: true,
              pagenum: i + 1,
              isjzz: false
            })
          }
          var a = that.bfstorelist
          a = (function (t) {
            for (var a = [], e = 0; e < t.length; e++) {
              if (-1 == a.indexOf(t[e])) {
                a.push(t[e])
              }
            }
            return a
          })((a = a.concat(t.data)))
          for (var e = 0; e < t.data.length; e++) {
            if ('0.0' == t.data[e].sales) {
              t.data[e].sales = '5.0'
            }
            var s = parseFloat(t.data[e].juli)
            console.log(s)
            console.log()
            if (s < 1000) {
              t.data[e].aa = s + 'm'
            } else {
              t.data[e].aa = (s / 1000).toFixed(2) + 'km'
            }
            t.data[e].aa1 = s
          }
          that.setData({
            storelist: a,
            bfstorelist: a
          })
          console.log(a)
        }
      })
    }
  }
}
</script>
<style>
@import './wdsc.css';
</style>
